/**
 * Created by Administrator on 2017/8/8.
 * Copyright 2017-2018 汉威.智慧环保事业部 Limited.
 * All rights reserved.
 */
package com.hw.one.collect;

import org.apache.log4j.xml.DOMConfigurator;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.MetaData;
import org.eclipse.jetty.webapp.WebAppClassLoader;
import org.eclipse.jetty.webapp.WebAppContext;

public class MainServer {

    private static final String DEFAULT_CONTEXT = "/";
    private static final String DEFAULT_WEBAPP_PATH = "/webapp";
    private static final int DEFAULT_PORT = 8081;

    public static void main(String[] args) throws Exception{

        Server server = new Server(DEFAULT_PORT);


        WebAppContext context = new WebAppContext();
        context.setContextPath(DEFAULT_CONTEXT);
        context.setBaseResource( Resource.newClassPathResource(DEFAULT_WEBAPP_PATH));

        MetaData metaData = context.getMetaData();
        Resource webappInitializer = Resource.newResource(MainServer.class.getProtectionDomain().getCodeSource().getLocation());
        metaData.addContainerResource(webappInitializer);

//        context.setClassLoader(new WebAppClassLoader(Thread.currentThread().getContextClassLoader(),context));

        server.setHandler(context);

        server.setStopAtShutdown(true);
        server.start();
        server.join();

    }
}
